import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;

public class FileWrite {
    public static void main(String[] args) {
        try(FileWriter writer = new FileWriter(new File("E:\\IO流练习\\InoutStream\\utf8.txt") , Charset.forName("utf16"))){
            writer.write("臣本布衣，躬耕于南阳，苟全性命于乱世，不求闻达于诸侯。");
            writer.write("先帝知臣谨慎，故临崩寄臣以大事也。",5,9);
            String str = "将军向宠，性行淑均，晓畅军事，试用于昔日，先帝称之曰能";
            char[] chars =str.toCharArray();
            writer.write(chars);
            writer.write(chars,5,12);
            System.out.println(writer.getEncoding());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
